import getpath
import os
import openpyxl
import re
import logging
def getdata_raw(filename):
    from openpyxl import load_workbook
    xl_book = load_workbook(filename=filename)
    table = xl_book.worksheets[0]
    data = []
    for row in table.values:
        r = []
        for one in row:
            if one is not None:
                r.append(one)
            else:
                r.append("")
        data.append(r)
    return data    
def zl_data(data):
    sample={}
    items=[]
    concs=[]
    eleBegin=False
    for i in range(len(data)):
        row=data[i]
        if row[0]=="Sample:":#new record begin
            sample["id"]=row[1]
        elif row[0]=="Report name":
            eleBegin=True
            continue
        if eleBegin:
            if row[0]=="":
                break
            items.append((row[0],""))
            concs.append(row[1])
    sample["items"]=items
    sample["concs"]=concs
    return[sample,]
def getdata(fname):
    data0=getdata_raw(fname)
    data=zl_data(data0)
    return data
def test_getdata():
    fname=os.path.join(getpath.getpath(),"pan.xlsx")
    data=getdata(fname)
    # print(data)
    return data
if __name__=="__main__":
    data=test_getdata()
    print(data)
    # for one in data:
    #     print(one["id"])
    # print(data[0])
    # print(data[1])
    # print(data[-2])
    # print(data[-1])